prevent deadlock when reconcileStaged runs restagePointerFiles
authorJoey Hess <joeyh@joeyh.name>
Mon, 22 Sep 2025 18:56:50 +0000 (14:56 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 22 Sep 2025 18:56:50 +0000 (14:56 -0400)
commit16d7432a2f6e085b6fec8ccce35bc41faea67745
tree5c280f6ed91ba3280e246d57c93fe30be2f60d6b
parentada2664b9c3893bd7c71e87845b6d0ae84f5cbd4
prevent deadlock when reconcileStaged runs restagePointerFiles

Fix hang that could occur when using git-annex adjust on a branch with a
number of files greater than annex.queuesize. Or potentially other
commands.

When reconcileStaged is running, the database is being opened. But
restagePointerFiles closes the database, and later writes to it. So it will
deadlock if called by reconcileStaged.

The deadlock occurred when the git queue happened to be full, causing
adding a call to restagePointerFiles to it to flush the queue and
restagePointerFiles to run at the wrong time.

Fixed by making reconcileStaged, when it populates or depopulates a pointer
file, arrange for restagePointerFiles to be run as a cleanup action, rather
than from the git queue.

But, what if restagePointerFiles is already in the git queue before
reconcileStaged is run? If it adds anything else to the git queue, causing
the queue to flush, it would still deadlock. To avoid this hypothetical
situation, added a Annex.inreconcilestaged, and made restagePointerFiles
check it and not do anything.

Note that, I did consider the simpler approach of only running
restagePointerFiles as a cleanup action, rather than from the git queue.
But see commit 6a3bd283b8af53f810982e002e435c0d7c040c59 for why it was made
to use the queue in the first place. I wanted to avoid tying this bug fix
to a behavior change.

Sponsored-by: mycroft
13 files changed:
Annex.hs
Annex/Content.hs
Annex/Content/PointerFile.hs
Annex/Ingest.hs
Annex/Link.hs
CHANGELOG
Command/PreCommit.hs
Command/Smudge.hs
Command/Unlock.hs
Database/Keys.hs
Types/CleanupActions.hs
doc/bugs/Unlock_filter_seems_to_deadlock_for_huge_worktree.mdwn
doc/bugs/Unlock_filter_seems_to_deadlock_for_huge_worktree/comment_3_6d01fe7c2a17669b2b9927e157d7d27f._comment [new file with mode: 0644]